package com.mf.cloud.controller;

import cn.hutool.core.util.IdUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * ClassName: PayCircuiController
 * Package: com.mf.cloud.controller
 *
 * @Author: lmf
 * @Create: 2024/3/17 9:53
 * @Version: 1.0
 * Description:  测试Circuit服务器熔断新增控制层
 */
@RestController // 返回json格式
@Tag(name="服务熔断和服务降级测试")
public class PayCircuitController {
    @GetMapping("/pay/circuit/{id}")
    @Operation(summary = "接口测试")
    public String myCircuit(@PathVariable("id") Integer id) {

        if (id == -4) throw new RuntimeException("不能为负数");
        if (id == 9999) {

            try {
                TimeUnit.SECONDS.sleep(66);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }
        return "hello,circuit! inputID" + id + "\t " + IdUtil.simpleUUID();
    }
}